<?php

class Admin_AdministrationController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
        // action body
    }

    public function gettranslateAction()
    {
        // action body
    	$this->_helper->layout->disableLayout ();
    	$this->_helper->removeHelper ( 'viewRenderer' );
    	
    	$principal = new Zend_Translate('tmx', APPLICATION_PATH.'/langues/principal.tmx','fr');
    	
    	$data['results'] = $principal->getMessages();
    	$data['total'] = count($principal->getMessages());
    	echo Zend_Json::encode($data);
    }

    public function ajoutpersonnesAction()
    {
    	// action body
    
    	$this->_helper->layout()->disableLayout();
    	$this->_helper->layout()->setLayout("gestionlayout");
    
    	$assignform = new Application_Form_ajoutpersonnes();
    	$this->view->form = $assignform;
    
    	$assignform->setAction('ajoutpersonnes');
    
    	$this->view->Formulaireajoutpersonnes = $assignform;
    
    	if ($this->_request->isPost ())
    	{
    		$formData = $this->_request->getPost ();
    		 
    		if ($assignform->isValid ( $formData ))
    		{
    			$datas = $formData;
    
    			$listclient= new Application_Model_DbTable_Personnes();
    
    			$data=array(
    					"nom" => $datas['nom'],
    					"prenom" => $datas['prenom'],
    					"login" => $datas['login'],
    					"motpass" => $datas['motpass'],
    					"mail" => $datas['mail']
    			);
    
    			$listclient->insert($data);
    			$this->_helper->redirector("gestionpersonne");
    
    		}
    	}
    }
    
    public function gestionpersonneAction()
    {
    	// action body
    
    	$this->_helper->layout()->disableLayout();
    	$this->_helper->layout()->setLayout("gestionlayout");
    
    	$header=array(
    			"idpersonnes" => "ID",
    			"nom" => "nom",
    			"prenom" => "prenom",
    			"login" => "login",
    			"motpass" => "motpass",
    			"mail" => "mail"
    	);
    	$usermapper= new Application_Model_Mapper_Personnes();
    	$select=$usermapper->fetchAllToArray();
    	$page=$this->_getParam('page',1);
    	$paginator = Zend_Paginator::factory($select);
    	$paginator->setItemCountPerPage(3);
    	$paginator->setCurrentPageNumber($page);
    
    	$this->view->header=$header;
    
    	$this->view->keyOfData="idpersonnes";
    
    	Zend_View_Helper_PaginationControl::setDefaultViewPartial('controls.phtml');
    	$this->view->paginator=$paginator;
    }
    
    public function deletepersonnesAction()
    {
    	$this->_helper->layout()->disableLayout();
    		
    	$this->view->id = $this->_getParam('id');
    	$this->view->messagedelate= "voulez-vous vraiment supprimer cette enregisterement ?";
    		
    	if ($this->_request->isPost ())
    	{
    		$formData = $this->_request->getPost ();
    
    		if ($formData['operation']=="oui")
    		{
    			$personne = new Application_Model_Personnes();
    
    			$personne->setIdpersonnes($formData['id']);
    
    			$personnes = new Application_Model_Mapper_Personnes();
    
    			$personnes->delete($personne);
    
    			$this->_helper->redirector('gestionpersonne','administration');
    		}
    		else
    		{
    			$this->_helper->redirector("gestionpersonne");
    		}
    	}
    }
    
    public function modifierpersonneAction()
    {
    	
    	$this->_helper->layout()->disableLayout();
		$this->_helper->layout()->setLayout("gestionlayout");
			
		$AFAffich = new  Application_Form_modifierpersonne();
		$AFAffich->setAction('modifierpersonne');
		$this->view->Formulairemodifierpersonne = $AFAffich;
			
		if ($this->getRequest()->isPost()) {
			$formData = $this->getRequest()->getPost();
			if ($AFAffich->isValid($formData)) {
			
				$albums = new Application_Model_DbTable_Personnes();

				$albums->update(array(
						"mail"=>$AFAffich->getValue('mail'),
						"motpass"=>$AFAffich->getValue('motpass'),
						"login"=>$AFAffich->getValue('login'),
						"prenom" => $AFAffich->getValue('prenom'),
						"nom" => $AFAffich->getValue('nom')),
						"idpersonnes = '".$AFAffich->getValue('idpersonnes')."'");
						
				$this->_helper->redirector("gestionpersonne");
			} else {
				$AFAffich->populate($formData);
			}
		} else {
			$id = $this->_getParam('id');
			if (!empty($id)) {
				$reqcomp = new Application_Model_DbTable_Personnes();
				$data=$reqcomp->fetchRow("idpersonnes = '".$id."'")->toArray();
					
				$AFAffich->populate($data);
			}
		}
    }
    
    public function ajoutserviceAction()
    {
    	// action body
    
    	$this->_helper->layout()->disableLayout();
    	$this->_helper->layout()->setLayout("gestionlayout");
    
    	$assignform = new Application_Form_Ajoutservice();
    	$this->view->form = $assignform;
    	$idapp=$this->_request->getParam("idapp");
    	if(!empty($idapp)){
    		$assignform->getElement("application_idapplication")->setAttrib("readonly","readonly");
    		$assignform->getElement("application_idapplication")->setValue($idapp);
    		$assignform->getElement("idapplication")->setValue($idapp);
    	}
    	
    	
    	$assignform->setAction('ajoutservice');
    
    	$this->view->Formulaireajoutservice = $assignform;
    
    	if ($this->_request->isPost ())
    	{
    		$formData = $this->_request->getPost ();
    		 
    		if ($assignform->isValid ( $formData ))
    		{
    			$datas = $formData;
    
    			$listclient= new Application_Model_DbTable_Services();
    			if(isset($datas['application_idapplication'])){
    				$datas['idapplication']=$datas['application_idapplication'];
    			}
    			
    			
    			$data=array(
    					"idservices" => $datas['idservices'],
    					"application_idapplication" => $datas['idapplication'],
    					"Description" => $datas['Description'],
    					"monmenu" => $datas['monmenu'],
    					"iconeCls_idiconeCls" => $datas['iconeCls_idiconeCls'],
    					"orderaff" => $datas['orderaff']
    			);
    
    			$listclient->insert($data);
    		
    			$this->_helper->redirector("gestionservice","administration","admin",array("id"=>$datas['idapplication']));
    
    		}
    	}
    }
    
    public function ajoutactionapplicationAction()
    {
    	// action body
    
    	$this->_helper->layout()->disableLayout();
    	$this->_helper->layout()->setLayout("gestionlayout");
    
    	$ajouteraction = new Application_Form_AjoutActionApplication();
    	$this->view->form = $ajouteraction;
    	$idapp=$this->_request->getParam("idservices");
    	if(!empty($idapp)){
    		$ajouteraction->getElement("services_idservices")->setAttrib("disabled","disabled");
    		$ajouteraction->getElement("services_idservices")->setValue($idapp);
    		$ajouteraction->getElement("idservices")->setValue($idapp);
    	}
    	 
    	$this->view->Formulaireajoutservice = $ajouteraction;
    
    	if ($this->_request->isPost ())
    	{
    		$formData = $this->_request->getPost ();
    		 
    		if ($ajouteraction->isValid ( $formData ))
    		{
    			$datas = $formData;
    
    			$Actionsapplication= new Application_Model_DbTable_Actionsapplication();
    			if(isset($datas['services_idservices'])){
    				$datas['idservices']=$datas['services_idservices'];
    			}
    			 
    			 
    			$data=array(
    					"idactions" => $datas['idactions'],
    					"services_idservices" => $datas['idservices'],
    					"url" => $datas['url'],
    					"nommenue" => $datas['nommenue'],
    					"iconeCls_idiconeCls" => $datas['iconeCls_idiconeCls'],
    					"orderaff" => $datas['orderaff']
    			);
    
    			$Actionsapplication->insert($data);
    
    			$this->_helper->redirector("gestionactionapplication","administration","admin",array("id"=>$datas['idactions']));
    
    		}
    	}
    }
    
    public function gestionserviceAction()
    {
    	// action body
    
    	$this->_helper->layout()->disableLayout();
    	$this->_helper->layout()->setLayout("gestionlayout");
    
    	$idapplication=$this->_request->getParam("id");
    	
    	$this->view->idapplication=$idapplication;
    	$header=array(
    			"idservices" => "ID",
    			"application_idapplication" => "Application",
    			"Description" => "Description",
    			"monmenu" => "Nom menu",
    			"iconeCls_idiconeCls" => "Icone",
    			"orderaff" => "Ordre",
    	);
    	
    	$usermapper= new Application_Model_DbTable_Services();
    	
    	if(!empty($idapplication)){
    		$select=$usermapper->fetchAll("application_idapplication='".$idapplication."'")->toArray();
    	}else{
    		$select=$usermapper->fetchAll()->toArray();
    	}
    	
    	$page=$this->_getParam('page',1);
    	$paginator = Zend_Paginator::factory($select);
    	$paginator->setItemCountPerPage(3);
    	$paginator->setCurrentPageNumber($page);
    
    	$this->view->header=$header;
    
    	$this->view->keyOfData="idservices";
    
    	Zend_View_Helper_PaginationControl::setDefaultViewPartial('controls.phtml');
    	$this->view->paginator=$paginator;
    }
    
    public function gestionactionapplicationAction()
    {
    	// action body
    
    	$this->_helper->layout()->disableLayout();
    	$this->_helper->layout()->setLayout("gestionlayout");
    
    	$idactions=$this->_request->getParam("id");
    	$this->view->idactions=$idactions;
    	$header=array(
    			"idactions" => "ID",
    			"services_idservices" => "Application",
    			"url" => "URL",
    			"nommenue" => "Nom menu",
    			"iconeCls_idiconeCls" => "Icone",
    			"orderaff" => "Ordre",
    	);
    	 
    	$usermapper= new Application_Model_DbTable_Actionsapplication();
    	if(!empty($idactions)){
    		$select=$usermapper->fetchAll("idactions='".$idactions."'")->toArray();
    	}else{
    		$select=$usermapper->fetchAll()->toArray();
    	}
    	 
    	$page=$this->_getParam('page',1);
    	$paginator = Zend_Paginator::factory($select);
    	$paginator->setItemCountPerPage(3);
    	$paginator->setCurrentPageNumber($page);
    
    	$this->view->header=$header;
    
    	$this->view->keyOfData="idactions";
    
    	Zend_View_Helper_PaginationControl::setDefaultViewPartial('controls.phtml');
    	$this->view->paginator=$paginator;
    }
    
    public function modifieractionapplicationAction()
    {
    	$this->_helper->layout()->disableLayout();
    	$this->_helper->layout()->setLayout("gestionlayout");
    
    	$AFAffich = new  Application_Form_Modifieractionapplication();
    	$AFAffich->setAction('modifieractionapplication');
    	//$AFAffich->setAction($this->_helper->url('gestionapplication','administration','admin'));
    	$this->view->Mofifieractionapplication = $AFAffich;
    
    	if ($this->getRequest()->isPost()) {
    		$formData = $this->getRequest()->getPost();
    
    		//var_dump($formData);exit;
    		if ($AFAffich->isValid($formData)) {
    
    			$albums = new Application_Model_DbTable_Actionsapplication();
    
    			$albums->update(array(
    					"orderaff"=>$AFAffich->getValue('orderaff'),
    					"iconeCls_idiconeCls"=>$AFAffich->getValue('iconeCls_idiconeCls'),
    					"nommenue"=>$AFAffich->getValue('nommenue'),
    					"url"=>$AFAffich->getValue('url'),
    					"services_idservices"=>$AFAffich->getValue('services_idservices')),
    					"idactions = '".$AFAffich->getValue('idactions')."'");
    
    			$this->_helper->redirector('gestionactionapplication');
    
    		} else {
    			$AFAffich->populate($formData);
    		}
    	} else {
    		$id = $this->_getParam('id');
    		if (!empty($id)) {
    			$reqcomp = new Application_Model_DbTable_Actionsapplication();
    			$data=$reqcomp->fetchRow("idactions = '".$id."'")->toArray();
    
    			$AFAffich->populate($data);
    		}
    	}
    }
    
    public function deleteactionapplicationAction()
    {
    	$this->_helper->layout()->disableLayout();
    
    	$this->view->id = $this->_getParam('id');
    	$this->view->messagedelate= "voulez-vous vraiment supprimer cette enregisterement ?";
    
    	if ($this->_request->isPost ())
    	{
    		$formData = $this->_request->getPost ();
    
    		if ($formData['operation']=="oui")
    		{
    			$personne = new Application_Model_Actionsapplication();
    
    			$personne->setIdactions($formData['id']);
    
    			$personnes = new Application_Model_Mapper_Actionsapplication();
    
    			$personnes->delete($personne);
    
    			$this->_helper->redirector('gestionactionapplication','administration');
    		}
    		else
    		{
    			$this->_helper->redirector("gestionactionapplication");
    		}
    	}
    }
    
    public function deleteserviceAction()
    {
    	$this->_helper->layout()->disableLayout();
    
    	$this->view->id = $this->_getParam('id');
    	$this->view->messagedelate= "voulez-vous vraiment supprimer cette enregisterement ?";
    
    	if ($this->_request->isPost ())
    	{
    		$formData = $this->_request->getPost ();
    
    		if ($formData['operation']=="oui")
    		{
    			$service = new Application_Model_Services();
    			
    			$service->setIdservices($formData['id']);
    
    			$services = new Application_Model_Mapper_Services();
    
    			$services->delete($service);
    
    			$this->_helper->redirector('gestionservice','Administration');
    		}
    		else
    		{
    			$this->_helper->redirector("gestionservice");
    		}
    	}
    }
    
    public function modifierserviceAction()
    {
    	$this->_helper->layout()->disableLayout();
    	$this->_helper->layout()->setLayout("gestionlayout");
    
    	$AFAffich = new  Application_Form_Modifierservice();
    	$AFAffich->setAction('modifierservice');
    	$this->view->Formulairemodifierservice = $AFAffich;
    
    	if ($this->getRequest()->isPost()) {
    		$formData = $this->getRequest()->getPost();
    
    		//var_dump($formData);exit;
    		if ($AFAffich->isValid($formData)) {
    			 
    			$albums = new Application_Model_DbTable_Services();
    
    			$albums->update(array(
    					"application_idapplication"=>$AFAffich->getValue('application_idapplication'),
    					"Description"=>$AFAffich->getValue('Description'),
    					"monmenu"=>$AFAffich->getValue('monmenu'),
    					"iconeCls_idiconeCls"=>$AFAffich->getValue('iconeCls_idiconeCls')),
    					"idservices = '".$AFAffich->getValue('idservices')."'");
    			 
    			$this->_helper->redirector('gestionservice');
    
    		} else {
    			$AFAffich->populate($formData);
    		}
    	} else {
    		$id = $this->_getParam('id');
    		if (!empty($id)) {
    			$reqcomp = new Application_Model_DbTable_Services();
    			$data=$reqcomp->fetchRow("idservices = '".$id."'")->toArray();
    
    			$AFAffich->populate($data);
    		}
    	}
    }
    
    public function ajoutapplicationAction()
    {
    	// action body
    
    	$this->_helper->layout()->disableLayout();
    	$this->_helper->layout()->setLayout("gestionlayout");
    
    	$assignform = new Application_Form_Ajoutapplication();
    	$this->view->form = $assignform;
    
    	$assignform->setAction('ajoutapplication');
    
    	$this->view->Formulaireajoutapplication = $assignform;
    
    	if ($this->_request->isPost ())
    	{
    		$formData = $this->_request->getPost ();
    		 
    		if ($assignform->isValid ( $formData ))
    		{
    			$datas = $formData;
    
    			$listclient= new Application_Model_DbTable_Application();
    
    			$data=array(
    					"idapplication" => $datas['idapplication'],
    					"BASEURL" => $datas['BASEURL'],
    					"Description" => $datas['Description'],
    					"nomapplication" => $datas['nomapplication'],
    			);
    
    			$listclient->insert($data);
    			$this->_helper->redirector("gestionapplication");
    
    		}
    	}
    }
    
    public function gestionapplicationAction()
    {
    	// action body
    
    	$this->_helper->layout()->disableLayout();
    	$this->_helper->layout()->setLayout("gestionlayout");
    
    	$header=array(
    			"idapplication" => "ID",
    			"nomapplication"=>"Nom application",
    			"BASEURL" => "URl",
    			"Description" => "Description",
    	);
    	$usermapper= new Application_Model_Mapper_Application();
    	$select=$usermapper->fetchAllToArray();
    	$page=$this->_getParam('page',1);
    	$paginator = Zend_Paginator::factory($select);
    	$paginator->setItemCountPerPage(3);
    	$paginator->setCurrentPageNumber($page);
    
    	$this->view->header=$header;
    
    	$this->view->keyOfData="idapplication";
    
    	Zend_View_Helper_PaginationControl::setDefaultViewPartial('controls.phtml');
    	$this->view->paginator=$paginator;
    }
    
    public function deleteapplicationAction()
    {
    	$this->_helper->layout()->disableLayout();
    
    	$this->view->id = $this->_getParam('id');
    	$this->view->messagedelate= "voulez-vous vraiment supprimer cette enregisterement ?";
    
    	if ($this->_request->isPost ())
    	{
    		$formData = $this->_request->getPost ();
    
    		if ($formData['operation']=="oui")
    		{
    			$service = new Application_Model_Application();
    			 
    			$service->setIdapplication($formData['id']);
    
    			$services = new Application_Model_Mapper_Application();
    
    			$services->delete($service);
    
    			$this->_helper->redirector('gestionapplication','Administration');
    		}
    		else
    		{
    			$this->_helper->redirector("gestionapplication");
    		}
    	}
    }
    
    public function modifierapplicationAction()
    {
    	$this->_helper->layout()->disableLayout();
    	$this->_helper->layout()->setLayout("gestionlayout");
    
    	$AFAffich = new  Application_Form_Modifierapplication();
    	$AFAffich->setAction('modifierapplication');
    	//$AFAffich->setAction($this->_helper->url('gestionapplication','administration','admin'));
    	$this->view->Formulairemodifierapplication = $AFAffich;
    
    	if ($this->getRequest()->isPost()) {
    		$formData = $this->getRequest()->getPost();
    
    		//var_dump($formData);exit;
    		if ($AFAffich->isValid($formData)) {
    
    			$albums = new Application_Model_DbTable_Application();
    
    			$albums->update(array(
    					"nomapplication"=>$AFAffich->getValue('nomapplication'),
    					"BASEURL"=>$AFAffich->getValue('BASEURL'),
    					"Description"=>$AFAffich->getValue('Description')),
    					"idapplication = '".$AFAffich->getValue('idapplication')."'");
    
    			$this->_helper->redirector('gestionapplication');
    
    		} else {
    			$AFAffich->populate($formData);
    		}
    	} else {
    		$id = $this->_getParam('id');
    		if (!empty($id)) {
    			$reqcomp = new Application_Model_DbTable_Application();
    			$data=$reqcomp->fetchRow("idapplication = '".$id."'")->toArray();
    
    			$AFAffich->populate($data);
    		}
    	}
    }
    
    public function ajouticoneAction()
    {
    	// action body
    
    	$this->_helper->layout()->disableLayout();
    	$this->_helper->layout()->setLayout("gestionlayout");
    
    	$assignform = new Application_Form_Ajouticone();
    	$this->view->form = $assignform;
    
    	$assignform->setAction('ajouticone');
    
    	$this->view->Formulaireajouticone = $assignform;
    
    	if ($this->_request->isPost ())
    	{
    		$formData = $this->_request->getPost ();
    		 
    		if ($assignform->isValid ( $formData ))
    		{
    			$datas = $formData;
    
    			$listclient= new Application_Model_DbTable_Iconecls();
    
    			$data=array(
    					"idiconeCls" => $datas['idiconeCls'],
    					"LabelICone" => $datas['LabelICone'],
    					"urlimage" => $datas['urlimage'],
    			);
    
    			$listclient->insert($data);
    			$this->_helper->redirector("gestionicone");
    
    		}
    	}
    }
    
    public function gestioniconeAction()
    {
    	// action body
    
    	$this->_helper->layout()->disableLayout();
    	$this->_helper->layout()->setLayout("gestionlayout");
    
    	$header=array(
    			"idiconeCls" => "ID",
    			"LabelICone" => "Label",
    			"urlimage" => "URl",
    	);
    	$usermapper= new Application_Model_Mapper_Iconecls();
    	$select=$usermapper->fetchAllToArray();
    	$page=$this->_getParam('page',1);
    	$paginator = Zend_Paginator::factory($select);
    	$paginator->setItemCountPerPage(3);
    	$paginator->setCurrentPageNumber($page);
    
    	$this->view->header=$header;
    
    	$this->view->keyOfData="idiconeCls";
    
    	Zend_View_Helper_PaginationControl::setDefaultViewPartial('controls.phtml');
    	$this->view->paginator=$paginator;
    }
    
    public function deleteiconeAction()
    {
    	$this->_helper->layout()->disableLayout();
    
    	$this->view->id = $this->_getParam('id');
    	$this->view->messagedelate= "voulez-vous vraiment supprimer cette enregisterement ?";
    
    	if ($this->_request->isPost ())
    	{
    		$formData = $this->_request->getPost ();
    
    		if ($formData['operation']=="oui")
    		{
    			$icone = new Application_Model_Iconecls();
    
    			$icone->setIdiconeCls($formData['id']);
    
    			$icones = new Application_Model_Mapper_Iconecls();
    
    			$icones->delete($icone);
    
    			$this->_helper->redirector('gestionicone','administration');
    		}
    		else
    		{
    			$this->_helper->redirector("gestionicone");
    		}
    	}
    }
    
    public function modifiericoneAction()
    {
    	$this->_helper->layout()->disableLayout();
		$this->_helper->layout()->setLayout("gestionlayout");
		 
		$AFAffich = new  Application_Form_Modifiericone();
		$AFAffich->setAction('modifiericone');
		$this->view->Formulairemodifiericone = $AFAffich;
		 
		if ($this->getRequest()->isPost()) {
			$formData = $this->getRequest()->getPost();
			if ($AFAffich->isValid($formData)) {
				
				$requet = new Application_Model_DbTable_Iconecls();
				 
				print_r($requet);
				$requet->update(array(
						"urlimage"=>$AFAffich->getValue('urlimage'),
						"LabelICone"=>$AFAffich->getValue('LabelICone')),
						"idiconeCls = '".$AFAffich->getValue('idiconeCls')."'");
				
				$this->_helper->redirector("gestionicone");
			} else {
				$AFAffich->populate($formData);
			}
		} else {
			$id = $this->_getParam('id');
			if (!empty($id)) {
				$modele = new Application_Model_DbTable_Iconecls();
				$data=$modele->fetchRow(" idiconeCls = '".$id."'")->toArray();
				 
				$AFAffich->populate($data);
			}
			 
		}
	
    }
 
    public function ajoutroleAction()
    {
    	// action body
    
    	$this->_helper->layout()->disableLayout();
    	$this->_helper->layout()->setLayout("gestionlayout");
    
    	$assignform = new Application_Form_Ajoutrole();
    	$this->view->form = $assignform;
    
    	$assignform->setAction('ajoutrole');
    
    	$this->view->Formulaireajoutrole = $assignform;
    
    	if ($this->_request->isPost ())
    	{
    		$formData = $this->_request->getPost ();
    		 
    		if ($assignform->isValid ( $formData ))
    		{
    			$datas = $formData;
    
    			$listclient= new Application_Model_DbTable_Role();
    
    			$data=array(
    					"idrole" => $datas['idrole'],
    			);
    
    			$listclient->insert($data);
    			$this->_helper->redirector("gestionrole");
    
    		}
    	}
    }
    
     public function gestionroleAction()
     {
    // action body
    
    $this->_helper->layout()->disableLayout();
    $this->_helper->layout()->setLayout("gestionlayout");
    
    $header=array(
    		"idrole" => "Identificateur",
    		
    );
    $usermapper= new Application_Model_Mapper_Role();
    $select=$usermapper->fetchAllToArray();
    $page=$this->_getParam('page',1);
    $paginator = Zend_Paginator::factory($select);
    $paginator->setItemCountPerPage(3);
    $paginator->setCurrentPageNumber($page);
    
    $this->view->header=$header;
    
    $this->view->keyOfData="idrole";
    
    Zend_View_Helper_PaginationControl::setDefaultViewPartial('controls.phtml');
    $this->view->paginator=$paginator;
    }
    
    public function deleteroleAction()
    {
	    $this->_helper->layout()->disableLayout();
	    
	    $this->view->id = $this->_getParam('id');
	    $this->view->messagedelate= "voulez-vous vraiment supprimer cette enregisterement ?";
    
    if ($this->_request->isPost ())
    {
	    $formData = $this->_request->getPost ();
	    
	    if ($formData['operation']=="oui")
	    {
	    $service = new Application_Model_Role();
	    
	    $service->setIdrole($formData['id']);
	    
	    $services = new Application_Model_Mapper_Role();
	    
	    $services->delete($service);
	    
	    $this->_helper->redirector('gestionrole','Administration');
	    }
    else
    {
    	$this->_helper->redirector("gestionrole");
   	   }
     }
   }
    
    public function ajoutassignementroleprojetAction()
    {
   // action body
   
    	$this->_helper->layout()->disableLayout();
    	$this->_helper->layout()->setLayout("gestionlayout");
    	
    	$assignform = new Application_Form_Ajoutassignementroleprojet();
    	$this->view->form= $assignform;
    	
    	$assignform->setAction('ajoutassignementroleprojet');
    	
    	$this->view->Formulaireajoutassignementroleprojet = $assignform;
    	
    	if (!empty($_POST)) {
    		$formData = $this->getRequest()->getPost();
    		if ($assignform->isValid($formData)) {
    			$checkb = $assignform->getValue('role_idrole');
    			$datas = new Application_Model_DbTable_PilotProjetRol();
    			foreach ($checkb as $key){
    				
    				$data=array(
    						 
    						"PILOT_PROJECT_idPILOT_PROJECT" => $formData["PILOT_PROJECT_idPILOT_PROJECT"],
    						"role_idrole"=> $key,
    				);

    				$datas->insert($data);
    			}
    			$this->_helper->redirector('gestionassignementroleprojet');
    		} else {
    			$assignform->populate($formData);
    		}
    	}
   }
   
   public function gestionassignementroleprojetAction()
   {
   // action body
   	//action body
   	$this->_helper->layout()->disableLayout();
   	$this->_helper->layout()->setLayout("gestionlayout");
   	
   	$header=array(
   			"idprojetrole" =>"ID",
   			"PILOT_PROJECT_idPILOT_PROJECT" =>"ID projet",
   			"role_idrole" =>"ID role",
   	);
   	
   	$usermapper= new Application_Model_Mapper_PilotProjetRol();
   	$select=$usermapper->fetchAllToArray();
   	$page=$this->_getParam('page',1);
   	$paginator = Zend_Paginator::factory($select);
   	$paginator->setItemCountPerPage(3);
   	$paginator->setCurrentPageNumber($page);
   	
   	$this->view->header=$header;
   	
   	$this->view->keyOfData="idprojetrole";
   	
   	Zend_View_Helper_PaginationControl::setDefaultViewPartial('controls.phtml');
   	$this->view->paginator=$paginator;
   }
   
   public function deleteassignementroleprojetAction()
   {
   $this->_helper->layout()->disableLayout();
   
   $this->view->id = $this->_getParam('id');
   $this->view->messagedelate= "voulez-vous vraiment supprimer cette enregisterement ?";
   
   if ($this->_request->isPost ())
   {
   $formData = $this->_request->getPost ();
   
   if ($formData['operation']=="oui")
   {
   $service = new Application_Model_PilotProjetRol();
   
   $service->setIdprojetrole($formData['id']);
   
   $services = new Application_Model_Mapper_PilotProjetRol();
   
   $services->delete($service);
   
   $this->_helper->redirector('gestionassignementroleprojet','Administration');
   }
   else
   {
   $this->_helper->redirector("gestionassignementroleprojet");
   		}
   	  }
   }
   
   public function modifierassignementroleprojetAction()
   {
   $this->_helper->layout()->disableLayout();
   $this->_helper->layout()->setLayout("gestionlayout");
   
   $AFAffich = new  Application_Form_Modifierassignementroleprojet();
   $AFAffich->setAction('modifierassignementroleprojet');
   
  // $AFAffich->setAction($this->_helper->url('gestionassignementroleprojet','administration','admin'));
   $this->view->FormulaireModifierassignementroleprojet = $AFAffich;
   
   if ($this->getRequest()->isPost()) {
   $formData = $this->getRequest()->getPost();
   
   //var_dump($formData);exit;
   if ($AFAffich->isValid($formData)) {
   
   $albums = new Application_Model_DbTable_PilotProjetRol();
   
   $albums->update(array(
   		"role_idrole"=>$AFAffich->getValue('role_idrole'),
   		"PILOT_PROJECT_idPILOT_PROJECT"=>$AFAffich->getValue('PILOT_PROJECT_idPILOT_PROJECT')),
   		"idprojetrole = '".$AFAffich->getValue('idprojetrole')."'");
   
   $this->_helper->redirector('gestionassignementroleprojet');
   
   } else {
   $AFAffich->populate($formData);
   }
   } else {
   $id = $this->_getParam('id');
   if (!empty($id)) {
   $reqcomp = new Application_Model_DbTable_PilotProjetRol();
   $data=$reqcomp->fetchRow("idprojetrole = '".$id."'")->toArray();
   
   $AFAffich->populate($data);
   }
   }
   }
   
   public function ajoutassignementrolepersonnetAction()
   {
   	// action body
   	 
   	$this->_helper->layout()->disableLayout();
   	$this->_helper->layout()->setLayout("gestionlayout");
   	 
   	$assignform = new Application_Form_Ajoutassignementrolepersonne();
   	$this->view->form= $assignform;
   	 
   	$assignform->setAction('ajoutassignementrolepersonnet');
   	 
   	$this->view->Formulaireajoutassignementroleprojet = $assignform;
   	 
   	if (!empty($_POST)) {
   		$formData = $this->getRequest()->getPost();
   		if ($assignform->isValid($formData)) {
   			$checkb = $assignform->getValue('role_idrole');
   			$datas = new Application_Model_DbTable_RolePersonne();
   			foreach ($checkb as $key){
   
   				$data=array(
   							
   						"personnes_idpersonnes" => $formData["personnes_idpersonnes"],
   						"role_idrole"=> $key,
   				);
   
   				$datas->insert($data);
   			}
   			$this->_helper->redirector('gestionassignementrolepersonne');
   		} else {
   			$assignform->populate($formData);
   		}
   	}
   }
    
   public function gestionassignementrolepersonneAction()
   {
		   	// action body
		   	//action body
		   	$this->_helper->layout()->disableLayout();
		   	$this->_helper->layout()->setLayout("gestionlayout");
		   
		   	$header=array(
		   			"idrolepersonne" =>"ID",
		   			"personnes_idpersonnes" =>"ID personne",
		   			"role_idrole" =>"ID role",
		   	);
		   
		   	$usermapper= new Application_Model_Mapper_RolePersonne();
		   	$select=$usermapper->fetchAllToArray();
		   	$page=$this->_getParam('page',1);
		   	$paginator = Zend_Paginator::factory($select);
		   	$paginator->setItemCountPerPage(3);
		   	$paginator->setCurrentPageNumber($page);
		   
		   	$this->view->header=$header;
		   
		   	$this->view->keyOfData="idrolepersonne";
		   
		   	Zend_View_Helper_PaginationControl::setDefaultViewPartial('controls.phtml');
		   	$this->view->paginator=$paginator;
   }
    
   public function deleteassignementrolepersonneAction()
   {
   	$this->_helper->layout()->disableLayout();
   	 
   	$this->view->id = $this->_getParam('id');
   	$this->view->messagedelate= "voulez-vous vraiment supprimer cette enregisterement ?";
   	 
   	if ($this->_request->isPost ())
   	{
   		$formData = $this->_request->getPost ();
   		 
   		if ($formData['operation']=="oui")
   		{
   			$service = new Application_Model_RolePersonne();
   			 
   			$service->setIdrolepersonne($formData['id']);
   			 
   			$services = new Application_Model_Mapper_RolePersonne();
   			 
   			$services->delete($service);
   			 
   			$this->_helper->redirector('gestionassignementrolepersonne','Administration');
   		}
   		else
   		{
   			$this->_helper->redirector("gestionassignementrolepersonne");
   		}
   	}
   }
    
   public function modifierassignementrolepersonneAction()
   {
   	$this->_helper->layout()->disableLayout();
   	$this->_helper->layout()->setLayout("gestionlayout");
   	 
   	$AFAffich = new  Application_Form_Modifierassignementrolepersonne();
   	$AFAffich->setAction($this->_helper->url('gestionassignementrolepersonne','Administration','Admin'));
   	$this->view->FormulaireModifierassignementrolepersonne = $AFAffich;
   	 
   	if ($this->getRequest()->isPost()) {
   		$formData = $this->getRequest()->getPost();
   		 
   		//var_dump($formData);exit;
   		if ($AFAffich->isValid($formData)) {
   			 
   			$albums = new Application_Model_DbTable_RolePersonne();
   			 
   			$albums->update(array(
   					"role_idrole"=>$AFAffich->getValue('role_idrole'),
   					"personnes_idpersonnes"=>$AFAffich->getValue('personnes_idpersonnes')),
   					"idrolepersonne = '".$AFAffich->getValue('idrolepersonne')."'");
   			 
   			$this->_helper->redirector('gestionassignementrolepersonne');
   			 
   		} else {
   			$AFAffich->populate($formData);
   		}
   	} else {
   		$id = $this->_getParam('id');
   		if (!empty($id)) {
   			$reqcomp = new Application_Model_DbTable_PilotProjetRol();
   			$data=$reqcomp->fetchRow("idprojetrole = '".$id."'")->toArray();
   			 
   			$AFAffich->populate($data);
   		}
   	}
   }
   
   public function getmenuebyprofileAction(){
   	
   	$this->_helper->layout()->disableLayout();
  	$this->_helper->viewRenderer->setNoRender(true);
   	
   	$user=Zend_Auth::getInstance()->getIdentity();
   	
   	
   	$useralldroit=new Application_Model_Mapper_Personnes();
   	
   	
   	$alldroit=$useralldroit->getAllInforRolesPersonne($user->idpersonnes);
   	
   	
   	$usermenue=array();
   	$i=0;
   	foreach ($alldroit as $valuerole){
   		foreach ($valuerole['services'] as $valueservice){
   			$menue=array();
   			$i++;
   			
   			$menue['text']= $valueservice['name'];
   			$menue['id']= $valueservice['application']."_$i"."_".$valueservice['baseurl'];
   			$menue['iconCls']=$valueservice['icone'];
   			
   			foreach ($valueservice['actions'] as $valueactions){
   				
   				$eltmenue=array();
   				
   				$eltmenue['text']=$valueactions['name'];
   				$eltmenue['id']=$valueactions['url'];
   				$eltmenue['iconCls']=$valueactions['icone'];
   				$menue['menu'][]=$eltmenue;
   			}
   			$usermenue[]=$menue;
   			
   		}
   				
   		
   		echo Zend_Json::encode($usermenue);
   		
   	
   	}
   	
   				
   				
   }
   
 public function assigneroleserviceAction()
   {
   	// action body
   
   	$this->_helper->layout()->disableLayout();
   	$this->_helper->layout()->setLayout("gestionlayout");
   
   	$assignrole = new Application_Form_assignerroleservice();
   	$this->view->form= $assignrole;
   
   	$assignrole->setAction('assigneroleservice');
   
   	$this->view->Formulaireassignerroleservice = $assignrole;
   
   	if (!empty($_POST)) {
   		$formData = $this->getRequest()->getPost();
   		if ($assignrole->isValid($formData)) {
   			$checkb = $assignrole->getValue('services_idservices');
   			$datas = new Application_Model_DbTable_DroitService();
   			foreach ($checkb as $key){
   
   				$data=array(
   
   						"idDroit_Service" =>  $formData["idDroit_Service"]."_".$key,
   						"role_idrole" => $formData["role_idrole"],
   						"services_idservices"=> $key,
   				);
   
   				$datas->insert($data);
   			}
   			$this->_helper->redirector('gestionassigneroleservice');
   		} else {
   			$assignrole->populate($formData);
   		}
   	}
   }
  
   public function gestionassigneroleserviceAction()
   {
		   	//action body
		   	$this->_helper->layout()->disableLayout();
		   	$this->_helper->layout()->setLayout("gestionlayout");
		   
		   	$header=array(
		   			"idDroit_Service" =>"ID",
		   			"role_idrole" =>"ID role",
		   			"services_idservices" =>"ID service",
		   	);
		   
		   	$roleservice= new Application_Model_Mapper_DroitService();
		   	$select=$roleservice->fetchAllToArray();
		   	$page=$this->_getParam('page',1);
		   	$paginator = Zend_Paginator::factory($select);
		   	$paginator->setItemCountPerPage(3);
		   	$paginator->setCurrentPageNumber($page);
		   
		   	$this->view->header=$header;
		   
		   	$this->view->keyOfData="idDroit_Service";
		   
		   	Zend_View_Helper_PaginationControl::setDefaultViewPartial('controls.phtml');
		   	$this->view->paginator=$paginator;
   }
   
   public function deleteassigneroleservice2Action()
   {
   	$this->_helper->layout()->disableLayout();
   	 
   	$this->view->id = $this->_getParam('id');
   	$this->view->messagedelate= "voulez-vous vraiment supprimer cette enregisterement ?";
   
   	if ($this->_request->isPost ())
   	{
   		$formData = $this->_request->getPost ();
   
   		if ($formData['operation']=="oui")
   		{
   
   
   			$activite = new Application_Model_DroitService();
   
   			$activite->setIdDroitService($formData['id']);
   
   			$activites = new Application_Model_Mapper_DroitService();
   
   			$activites->delete($activite);
   
   			$this->_helper->redirector('gestionassigneroleservice','administration');
   		}
   		else
   		{
   			$this->_helper->redirector("gestionassigneroleservice");
   		}
   
   	}
   }
   
}